Another way to create a Channel is via Channel().

This looks like a constructor, but Channel is an interface, not a class. In reality, Channel() is simply a top-level factory function, sharing a name with the interface.

It takes a parameter indicating how send() should work:

  • 0 indicates that send() should block until the consumer of the channel is able to receive the object

  • Channel.UNLIMITED means that send() always returns immediately, and the channel will buffer objects up until the limit of available memory

  • Channel.CONFLATED means that send() always returns immediately, but only the last object sent is buffered — all previous objects are lost

  • Any other positive Int value (but less than Channel.UNLIMITED) means that the channel will buffer that number of elements, and send() might block until a consumer can receive objects if that buffer is full (Channel.BUFFERED uses a default capacity of 64 elements)

You can learn more about this in:
Tags:
Run Edit